# -*- mode: python; -*-

#
# Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
#
# Placeholder for fabric-ansible Sconscript

import os

Import('CfgmEnv')
env = CfgmEnv.Clone()

#
# Deprecated
# Builds into build/<optimization>
#
subdirs=[
    'ansible-playbooks',
]

setup_sources = [
           'setup.py',
           'MANIFEST.in',
           'run_tests.sh',
           'requirements.txt',
           'test-requirements.txt',
           '.testr.conf',
           '.coveragerc',
           'test',
          ]

setup_sources_rules = []
for file in setup_sources:
    setup_sources_rules.append(
        env.Install(Dir('.'), "#controller/src/config/fabric-ansible/" + file))

local_sources = [
    'job_manager/__init__.py',
    'job_manager/job_mgr.py',
    'job_manager/job_handler.py',
    'job_manager/job_result_handler.py',
    'job_manager/job_exception.py',
    'job_manager/job_utils.py',
    'job_manager/logger.py',
    'job_manager/job_log_utils.py',
    'job_manager/playbook_helper.py',
    'job_manager/sandesh_utils.py',
    'job_manager/job_messages.py',
    'job_manager/fabric_logger.py',
    'job_manager/job_manager_logger.py',
]

local_sources_rules = []
for file in local_sources:
    local_sources_rules.append(
        env.Install("job_manager",
                    "#controller/src/config/fabric-ansible/" + file))

job_pkg = env.SandeshGenPy('job.sandesh', 'job_manager/sandesh/', False)

cd_cmd = 'cd ' + Dir('.').path + ' && '
sdist_depends = []
sdist_depends.extend(setup_sources_rules)
sdist_depends.extend(local_sources_rules)
sdist_depends.extend(job_pkg)
sdist_gen = env.Command('dist/fabric_ansible-0.1dev.tar.gz', 'setup.py', cd_cmd + 'python setup.py sdist')

env.Depends(sdist_gen, sdist_depends)
env.Default(sdist_gen)

# Documentation
doc_files = []
doc_files += env.SandeshGenDoc('job.sandesh')
doc_files += env['CFGM_DOC_FILES']

if 'install' in BUILD_TARGETS:
    install_cmd = env.Command(None, 'setup.py',
                              cd_cmd + 'python setup.py install %s' %
                              env['PYTHON_INSTALL_OPT'])
    env.Depends(install_cmd, sdist_depends)
    env.Alias('install', install_cmd)

env.Alias('install', env.Install(env['INSTALL_CONF'],
          'contrail-fabric-ansible.conf'))
env.Alias('install', env.Install(
    env['INSTALL_MESSAGE_DOC'] + '/contrail-fabric-ansible/', doc_files))

test_target = env.SetupPyTestSuite(sdist_gen,
                                   '/config/api-server/dist/contrail-api-server-0.1dev.tar.gz')

CfgmEnv.SConscript(dirs=subdirs, exports='CfgmEnv', duplicate = 0)
